"use strict";
const { Model } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
  class Product extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      Product.belongsTo(models.Factory, {
        foreignKey: "factory_id",
        allowNull: true,
      });
      // Product.hasMany(models.Shop,{
      //   foreignKey:'product_id'
      // })
      Product.hasMany(models.Inventory, {
        foreignKey: "product_id",
      });
      // Product.belongsTo(models.Contract,{
      //   foreignKey:'contract_id'
      // })
      Product.belongsTo(models.Staff, {
        foreignKey: "checker_id",
        as: "checker",
        allowNull: true,
      });

      // define association here
    }
  }
  Product.init(
    {
      type: DataTypes.STRING,
      name: DataTypes.STRING,
      price: DataTypes.FLOAT,
      product_description: DataTypes.STRING,
      product_maintenance: DataTypes.INTEGER,
      approval_status: {
        type: DataTypes.STRING,
        defaultValue: "待审核",
      },
      check_sug: DataTypes.STRING,
      // check_staffs:DataTypes.TEXT
    },
    {
      sequelize,
      modelName: "Product",
      tableName: "products",
    }
  );
  return Product;
};
